﻿@page
@model FDSimpleModelGenerator.Pages.UploadModel
@{
}

@Html.AntiForgeryToken()
<form name="formUpload" action="Upload?handler=Server" method="post">
    <div class="row">
        <label class="col-md-2">文件名</label>
        <input class="col-md-5" name="Name" value="Name" />
        <input class="col-md-5" multiple="multiple" type="file" name="FileNames" />
    </div>
    <div class="row">
        <button type="button" id="btnOk" class="offset-5 col-md-5 btn-primary">ok</button>
    </div>
</form>
@section Scripts
{
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/js/jquery.extend.js"></script>
    <script>
        // 请求前先设置好antitoken
        $.ajaxSetup({
            beforeSend: function (xhr) {
                xhr.setRequestHeader("RequestVerificationToken",
                    $('input:hidden[name="__RequestVerificationToken"]').val());
                //xhr.setRequestHeader("Content-Type", "application/json");
            }
        });
        $("#btnOk").click(e => {
            var form = $("form[name=formUpload]");
            var url = form.attr("action");
            var data = $.serializeForm("form[name=formUpload]");
            console.log(data);
            $.ajax({
                url: url,
                data: data,
                type: "POST",
                processData: false,
                contentType: false,
                cache: false,
                success: res => {
                    console.log(res);
                }
            });
        });
    </script>

}
